package com.itheima.health.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckItemService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CheckItemController {
    @Reference
    private CheckItemService checkItemService;

    @GetMapping("checkitem/findAll")
    public Result findAll() {
        List<CheckItem> list = checkItemService.list();
        System.out.println("查询所有"+list);
        return new Result(list);
    }
    //分页查询
    @PostMapping("checkitem/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        return new Result(checkItemService.findPage(queryPageBean));
    }
    @DeleteMapping("checkitem/deleteCheckItemById/{id}")
    public Result  deleteCheckItemById(@PathVariable("id") int id){
        ObjectMapper objectMapper = new ObjectMapper();

        return  new Result(checkItemService.updateCheckItemById(id));  //   业务代码实现
    }
    @PostMapping("checkitem/add")
    public Result  add(@RequestBody CheckItem checkItem){
        //   checkItem   存id  ---   托管态  update  xxx  set  xxx? x?> x  where  id  = ?
        //  checkitem  没有id      -- 瞬时态  没有 id                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           save  操作  insert  ...
        return  new Result(checkItemService.saveOrUpdate(checkItem));  //   业务代码实现
    }

    @GetMapping("checkitem/findDeleted")
    public Result findDeleted() {
        return new Result(checkItemService.findDeleted());
    }
    @DeleteMapping("checkitem/recoverDeleted/{id}")
    public Result recoverDeleted(@PathVariable("id") Integer id){
        return new Result(checkItemService.recoverDeleted(id));
    }
}
